package ca.etsmtl.logti.log619.lab05.filter;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.mail.internet.MimeMessage;

import ca.etsmtl.logti.log619.lab05.utilities.EmailSplicer;

public class BadEncodingFilter implements EmailFilter {

	final String NAME = "Bad Encoding Filter";
	
	@Override
	public String getFilterName() {
	
		return this.NAME;
	}

	@Override
	public byte checkSpam(MimeMessage message) {
		
		byte spamValue = CANT_SAY;
		
		try {
			
			EmailSplicer.getMessageContent(message);
			
			// Testing sender email, generate AddressException if not in good format
			message.getFrom();
			
		} catch (AddressException e) { spamValue = 100; }
		  catch (UnsupportedEncodingException e) { spamValue = 100; }
		  catch (IOException e) { e.printStackTrace(); }
		  catch (MessagingException e) { spamValue = 50; }
		
		return spamValue;
	}

	@Override
	public byte getConfidenceLevel() {

		return 100;
	}

	@Override
	public boolean enabled() {
		
		return true;
	}

}
